package com.yunsoft;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.sun.tracing.dtrace.ModuleAttributes;
import com.yunsoft.pojo.Student;
//定义当前对象类为控制器类
@Controller
public class HelloController {
	//hander Maping value 定义到处理到那个方法上，method定义Service处理的请求类型
	@RequestMapping(value="/hello",method=RequestMethod.GET)
	public String hello(ModelMap model){//向view创建数据的对象
		System.out.println("进入了方法");
		model.addAttribute("message", "Hello Spring MVC Framework!");//传递的模型数据的key赋值。
		return "hello";//呈现视图的模型名称
	}
	
	@RequestMapping(value="/student",method=RequestMethod.GET)
	public String student(ModelMap model){//向view创建数据的对象
		System.out.println("进入了方法");
		model.addAttribute("student", "Hello Spring MVC Framework!");//传递的模型数据的key赋值。
		return "student";//呈现视图的模型名称
	}
	
	@RequestMapping(value="/addStudent",method=RequestMethod.POST)
	public String addStudent(@ModelAttribute("SpringWeb") Student student,ModelMap map){
		map.addAttribute("name",student.getName() );
		map.addAttribute("age",student.getAge() );
		map.addAttribute("clas",student.getClas() );
		return "result";
	}
	
	@RequestMapping(value="/redirect",method=RequestMethod.GET)
	public String redirect(){
		//重定向到finalPage页面
		return "redirect:finalPage";
	}
	
	@RequestMapping(value="/finalPage",method=RequestMethod.GET)
	public String finalPage(){
	
		return "finalPage";
	}
	
	//重定向到一个静态页面上
	  @RequestMapping(value = "/staticPage", method = RequestMethod.GET)
	   public String redirects() {     
	      return "redirect:/pages/final.html";
	   }
	
}
